package com.cgsd.heyu.common;

import com.android.library.utils.SharedPreferencesHelper;
import com.cgsd.heyu.entity.UploadTokenEntity;
import com.qiniu.android.storage.Configuration;
import com.qiniu.android.storage.UploadManager;

/**
 * @author xiaoxing
 * Description 七牛云相关数据
 * CreateData: 2020/11/17
 */
public class FileTokenConfig {
    private volatile static FileTokenConfig fileTokenConfig;

    /**
     * 多媒体七牛云数据相关
     */
    public UploadTokenEntity multiMediaTokenData(){
        return SharedPreferencesHelper.getBeanByFastJson(Constants.ShareKeyValue.MULTIMEDIA_TOKEN_DATA,UploadTokenEntity.class);
    }

    /**
     * 图片七牛云数据相关
     */
    public UploadTokenEntity imageTokenData(){
        return SharedPreferencesHelper.getBeanByFastJson(Constants.ShareKeyValue.IMAGE_TOKEN_DATA,UploadTokenEntity.class);
    }

    /**
     * 七牛云管理
     */
    private UploadManager uploadManager;


    private FileTokenConfig(){}

    public static FileTokenConfig getInstance(){
        if (fileTokenConfig == null){
            synchronized (FileTokenConfig.class){
                if (fileTokenConfig == null){
                    fileTokenConfig = new FileTokenConfig();
                }
            }
        }
        return fileTokenConfig;
    }


    /**
     * 获取七牛云管理
     * @return
     */
    public UploadManager getUploadManager() {
        if (uploadManager == null){
            Configuration config = new Configuration.Builder()
                    .useHttps(false)
                    .connectTimeout(10)
                    .responseTimeout(10)
                    .build();
            uploadManager = new UploadManager(config);
        }
        return uploadManager;
    }

}
